package com.sk.cardeal.act.manage.act;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sk.cardeal.R;
import com.sk.cardeal.adapter.ChooseAdapter;
import com.sk.cardeal.adapter.WarehourseAdapter;
import com.sk.cardeal.base.BaseActivity;
import com.sk.cardeal.entity.WareListBean;
import com.sk.cardeal.view.TitleView;

import java.util.List;

import butterknife.BindView;

/**
 * Created by sk on 2018/3/21.
 */

public class ChooseWarehouseActivity extends BaseActivity implements BaseQuickAdapter.OnItemClickListener {

    @BindView(R.id.title_view)
    TitleView titleView;
    @BindView(R.id.data_ryc)
    RecyclerView dataRyc;
    private String result = "";
    List<WareListBean.ResultListBean> wareDataList;

    @Override
    protected int getContentView() {
        return R.layout.activity_choose_worehouse;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titleView.setMyCallBack(this);
        result = getIntent().getStringExtra("data");
        WareListBean wareListBean = JSON.parseObject(result, WareListBean.class);
        wareDataList = wareListBean.getResultList();

        dataRyc.setLayoutManager(new LinearLayoutManager(mContext));

        WarehourseAdapter adapter = new WarehourseAdapter(R.layout.item_ware_hourse,wareDataList);

        dataRyc.setAdapter(adapter);

        adapter.setOnItemClickListener(this);
    }

    @Override
    public void clickTitle(int i) {
        super.clickTitle(i);
        switch (i){
            case 1:
                finish();
                break;
        }
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        Intent intent = new Intent();
        intent.putExtra("data",wareDataList.get(position));
        setResult(RESULT_OK,intent);
        finish();
    }
}
